#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int Judge(char* s1, char* s2)
{
    int i = 0; int j = 0;
    char temp = 0;
    for (i = 0; i < 5; i++)
    {
        temp = *s1;
        for (j = 0; j < 4; j++)
        {
            *(s1 + j) = *(s1 + 1 + j);
        }
        *(s1 + 4) = temp;
        if (s1 == s2)
        {
            return 1;
        }
        else
            break;
    }
    return 0;

}
int main()
{
    char s1[5]; char s2[5];
    for (int i = 0; i < 5; i++)
    {
        scanf("%d", &s1[i]);
    }
    for (int i = 0; i < 5; i++)
    {
        scanf("%d", &s2[i]);
    }
    int a=Judge(s1,s2);
    printf("%d\n", a);

    return 0;
}